home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Newswatcher 2.0b22 / NW Source / Source / spin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  1.8 KB  |  77 lines  |  [TEXT/MMCC]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     spin.c
  4.  
  5.     This reusable module handles animated cursors.
  6.     
  7.     Copyright © 1994, Northwestern University.
  8.  
  9. ----------------------------------------------------------------------------*/
  10.  
  11. #include "def.h"
  12. #include "spin.h"
  13. #include "resutil.h"
  14.  
  15.  
  16.  
  17. static Handle gAcur = nil;            /* handle to animated cursor resource */
  18.  
  19.  
  20.  
  21. /*----------------------------------------------------------------------------
  22.     InitCursorCtl 
  23.     
  24.     Initialize an animated cursor.
  25.             
  26.     Entry:    acur = handle to 'acur' resource, or nil to use 'acur' id=0.
  27. ----------------------------------------------------------------------------*/
  28.  
  29. pascal void InitCursorCtl (Handle acur)
  30. {
  31.     short numFrames, i, id;
  32.     CursHandle cursorHandle;
  33.     OSErr err = noErr;
  34.  
  35.     if (acur == nil) {
  36.         err = MyGetResource('acur', 0, &gAcur);
  37.         if (err != noErr) return;
  38.     } else {
  39.         gAcur = acur;
  40.     }
  41.     numFrames = *(short*)(*gAcur);
  42.     for (i = 0; i < numFrames; i++) {
  43.         id = *(short*)(*gAcur + 4*i + 4);
  44.         cursorHandle = GetCursor(id);
  45.         *(CursHandle*)(*gAcur + 4*i + 4) = cursorHandle;
  46.     }
  47.     *(short*)(*gAcur + 2) = 0;
  48. }
  49.  
  50.  
  51.  
  52. /*----------------------------------------------------------------------------
  53.     SpinCursor 
  54.     
  55.     Spin an animated cursor.
  56.             
  57.     Entry:    num = spin control parameter.
  58. ----------------------------------------------------------------------------*/
  59.  
  60. pascal void SpinCursor (short num)
  61. {
  62.     short numFrames, curFrame, curCounter;
  63.     CursHandle cursorHandle;
  64.  
  65.     if (gAcur == nil) {
  66.         InitCursorCtl(nil);
  67.         if (gAcur == nil) return;
  68.     }
  69.     numFrames = *(short*)(*gAcur);
  70.     curCounter = *(short*)(*gAcur + 2);
  71.     curCounter = (curCounter + num) % (numFrames * 32);
  72.     *(short*)(*gAcur + 2) = curCounter;
  73.     curFrame = curCounter / 32;
  74.     cursorHandle = *(CursHandle*)(*gAcur + 4 + 4*curFrame);
  75.     SetCursor(*cursorHandle);
  76. }
  77.